package com.cqsd.entry.a.b.c;

import com.cqsd.UserService;
import com.cqsd.ioc.annotation.Autowrite;
import com.cqsd.ioc.annotation.Component;
import com.cqsd.ioc.annotation.Value;
import com.cqsd.ioc.trait.use.InitalizingBean;

import java.util.List;

/**
 * @author caseycheng
 * @date 2023/3/13-04:41
 **/
@Component
public class EmpService implements InitalizingBean {
    @Autowrite
    private UserService userService;
    @Value("${hello}")
    private Integer h;
    @Value("${app.config.name.type}")
    private String t;

    {
        String msg = userService == null ? "空" : "非空";
        System.out.println("emp: userService现在的状态" + msg);
        System.out.println("h = " + h);
        System.out.println("t = " + t);
    }

    @Override
    public void afterPropertiesSet() {
        String msg = userService == null ? "空" : "非空";
        System.out.println("emp: userService现在的状态" + msg);
        System.out.println("h = " + h);
        System.out.println("t = " + t);
        System.out.println("emp = " + this);
        System.out.println("userService = " + userService);
        fac();
    }

    public void fac() {
        var num = 5;
        final var face = getFace(num);
        final var sum = getSum(num);
        System.out.println(num + "的阶乘" + face);
        System.out.println(num + "的和是:" + sum);
        sord();
    }

    public int getFace(int num) {
        if (num == 1) {
            return num;
        } else {
            return num * getFace(num - 1);
        }
    }

    public int getSum(int num) {
        if (num == 1) {
            return num;
        } else {
            return num + getSum(num - 1);
        }
    }

    public void sord() {
        final var list = new java.util.ArrayList<>(List.of(1, 2, 3, 4, 2, 1, 5, 9, 7, 5));
        list.sort(Integer::compareTo);
        System.out.println(list);
    }


}
